
import axios from 'axios';
import React, { useState,useEffect} from 'react';
import { DatePicker, Space ,Select} from 'antd';

const { Option } = Select;
let Wd = function(){
    const [data1,setData1] = useState([])
    const [data,setData] = useState([])
    var sz
    var id
    function handleChange(value) {
        console.log(`selected ${value}`);
    }
    useEffect(() => {
        const FetchData = async () => {
            const result = await axios.post(
                'http://crm.cimns.com/index.php/admin/users/getUserList'
            );
            
            setData1(result.data.data)
        };
        FetchData();
        const FetchData1 = async () => {
            const result = await axios.post(
                'http://crm.cimns.com/index.php/oa/log/index',{
                    send_user_id: '',
                    create_time: 1617667200,
                    category_id: 3,
                    page: 1,
                    limit: 15,
                    by: 'notRead'
                });
            
            setData(result.data.data.list)
        };
        FetchData1();
    },[])
    function onChange(date, dateString) {
        console.log(date, dateString);
    }
    function click(index){
        var hfnr=document.querySelectorAll('.hfnr')
        for (let i = 0; i < hfnr.length; i++) {
            hfnr[i].style.display='none'
            var a = true
        }
        if (a) {
            hfnr[index].style.display='block'
            a = false
        }else{
            hfnr[index].style.display='none'
            a = true
        }
    }
    function click1(index){
        var hfnr=document.querySelectorAll('.hfnr')
        hfnr[index].style.display='none'
    }
    for (let i = 0; i < data.length; i++) {
        if (data[i].create_user_info.thumb_img === '') {
          data[i].create_user_info.thumb_img = 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3935552106,710264437&fm=26&gp=0.jpg'
        }
        for (let j = 0; j < data[i].replyList.length; j++) {
            if (data[i].replyList[j].userInfo.thumb_img === '') {
                data[i].replyList[j].userInfo.thumb_img = 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3935552106,710264437&fm=26&gp=0.jpg'
            }
        
        }
      };
    function handleChange(value){
        console.log(value);
        id = value
        const FetchData1 = async () => {
            const result = await axios.post(
                'http://crm.cimns.com/index.php/oa/log/index',{
                    category_id: id,
                    create_time: '',
                    page: 1,
                    limit: 15,
                    by:'notRead',
                });
            
            setData(result.data.data.list)
        };
        FetchData1();
    }
    function onChange(value){
        console.log(value);
        sz=+new Date(value);

        const FetchData1 = async () => {
            const result = await axios.post(
                'http://crm.cimns.com/index.php/oa/log/index',{
                    create_time: sz,
                    page: 1,
                    limit: 15,
                    by: 'notRead'
                });
            
            setData(result.data.data.list)
        };
        FetchData1();
    }
    console.log(data);
    
    return(
        <div>
            <div style={{marginBottom:'25px'}}>
                <span>发起人</span>
                
                <Select
                    // defaultValue="请选择" 
                    style={{ width: '140px',margin: '0px 10px'}}
                    placeholder="请选择"
                    //  onChange={handleChange}
                    optionLabelProp="label"
                >
                    {data1.map((item,index)=>{
                        return(
                            <Option key={index} value={item.realname} label={item.realname} >
                                
                            </Option>
                        )
                    })}
                </Select>
                <span>提交时间</span>
                <Space direction="vertical" style={{width:'140px',margin: '0px 10px'}}>
                    <DatePicker onChange={onChange} />
                </Space>
                <span>类型</span>
                <Select defaultValue="请选择" style={{ width: 120 }} onChange={handleChange}>
                     {/* onChange={HandleChange3} */}
                    {/* stop_type: */}
                    <Option value="0">全部</Option>
                    <Option value="1">日报</Option>
                    <Option value="2">周报</Option>
                    <Option value="3">月报</Option>
                </Select>
            </div>
            <div>
            {data.map((item,index) => (
                <div key={index} className = 'rz'>
                    <div className='clearfix' style={{marginBottom : 10+'px'}}>
                        <div><img alt='0' src={item.create_user_info.thumb_img}/></div>
                        <div>
                            <span>{item.create_user_info.realname}</span>
                            <span>{item.action_content}</span>
                            <p>{item.create_time} &nbsp;&nbsp;&nbsp; 0各部门，0个同事</p>
                        </div>
                        
                    </div>
                    <ul>
                        <li>今日工作内容：<span>{item.content}</span></li>
                        <li>明日工作内容：<span>{item.tomorrow}</span></li>
                        <li>遇到的问题：<span>{item.question}</span></li>
                    </ul>
                    <div>
                        <ol>
                            {item.replyList.map((item1,index) => ( 
                                <div key ={index} className = 'rz1'>
                                    <div className='clearfix' style={{marginBottom : 10+'px'}}>
                                        <div><img alt='0' src={item1.userInfo.thumb_img}/></div>
                                        <div>
                                            <span>{item1.realname}</span>
                                            <span>{item1.create_time}</span>
                                            <p>{item1.content}</p>
                                        </div>
                                    </div>


                                    
                                </div>
                            ))}
                            <div className="hf">
                                <button onClick={()=>{click(index)}}>回复</button>
                                
                            </div>
                            <div className = 'hfnr'>
                                <div>
                                    <textarea placeholder="请输入内容" />
                                </div>
                                <div className="clearfix">
                                    <img alt='0' src=""/>
                                    <div>
                                        <span>回复</span>
                                        <span onClick={()=>{click1(index)}}>取消</span>
                                    </div>
                                </div>
                            </div>
                        </ol>
                    </div>
                </div> 
            ))}
            <div style={{fontSize:'12px',textAlign: 'center',color:'#999'}}>没有更多啦</div>
            </div>
        </div>
    )
}
export default Wd